package org.hamster.multidropbox.main.model
{
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.net.URLRequestMethod;
	
	import flashx.textLayout.tlf_internal;
	
	import mx.collections.ArrayCollection;
	
	import org.hamster.common.puremvc.proxies.BaseRemoteProxy;
	import org.hamster.common.services.ConfigService;
	import org.hamster.multidropbox.main.utils.AppUtil;
	import org.hamster.multidropbox.main.utils.PureMVCHelper;
	import org.hamster.multidropbox.main.vo.AppConfigVO;
	import org.hamster.multidropbox.main.vo.IStorableVO;
	import org.puremvc.as3.patterns.proxy.Proxy;
	
	public class AppStorageProxy extends BaseRemoteProxy
	{
		public static const NAME:String = "org.hamster.multidropbox.main.model.AppConfigProxy";
		
		public function AppStorageProxy(name:String = null, loadingText:String = "")
		{
			super(name, loadingText);
		}
		
		public function saveData(storableVOList:ArrayCollection, fileName:String):void
		{
			var rootFolder:String = AppUtil.rootFolder;
			var rootXML:XML = <content></content>;
			for each (var storableVO:IStorableVO in storableVOList) {
				rootXML.appendChild(storableVO.encodeXML());
			}
			
			var fs:FileStream = new FileStream();
			fs.openAsync(new File(File.applicationDirectory.nativePath + File.separator + rootFolder + File.separator + fileName), FileMode.WRITE);
			fs.writeUTFBytes(rootXML.toXMLString());
			fs.close();
		}
		
		public function loadData(fileName:String):void
		{
			this.load(AppUtil.rootFolder + File.separator + fileName, null, URLRequestMethod.GET);
		}
		
	}
}